<!--
 * @Description: 渠道码统计
 * @Author: DXV-RGWU-TUFH-RFCY-IEGMYY
 * @Date: 2022-09-02 09:21:18
 * @LastEditTime: 2023-08-01 18:31:35
 * @LastEditors: DXV-RGWU-TUFH-RFCY-IEGMYY
-->

<template>
  <div class="lb-channel-qr-count">
    <top-nav />
    <div class="page-main">
      <el-row class="page-search-form">
        <el-form
          @submit.native.prevent
          :inline="true"
          :model="searchForm"
          ref="searchForm"
        >
          <el-form-item label="编码" prop="code">
            <el-input
              v-model="searchForm.code"
              placeholder="请输入编码"
            ></el-input>
          </el-form-item>
          <el-form-item label="渠道商" prop="channel_name">
            <el-input
              v-model="searchForm.channel_name"
              placeholder="请输入渠道商姓名"
            ></el-input>
          </el-form-item>
          <el-form-item label="其他筛选" prop="type">
            <el-select
              @change="getTableDataList(1)"
              v-model="searchForm.type"
              placeholder="请选择"
            >
              <el-option
                v-for="item in base_type"
                :key="item.id"
                :label="item.title"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <lb-button
              size="medium"
              type="primary"
              icon="el-icon-search"
              style="margin-right: 5px"
              @click="getTableDataList(1)"
              >{{ $t('action.search') }}</lb-button
            >
            <lb-button
              size="medium"
              icon="el-icon-refresh-left"
              style="margin-right: 5px"
              @click="resetForm('searchForm')"
              >{{ $t('action.reset') }}</lb-button
            >
          </el-form-item>
        </el-form>
      </el-row>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="tableData"
        :header-cell-style="{ background: '#f5f7fa', color: '#606266' }"
        style="width: 100%"
      >
        <el-table-column prop="title" label="渠道码名称" width="150" fixed>
        </el-table-column>
        <el-table-column prop="code" label="编码" min-width="150">
        </el-table-column>
        <el-table-column prop="cate_name" label="所属类目" min-width="150">
        </el-table-column>
        <el-table-column prop="nickName" label="绑定人员" min-width="120">
        </el-table-column>
        <el-table-column prop="channel_name" label="渠道商姓名" min-width="120">
        </el-table-column>
        <el-table-column prop="balance" label="渠道分成" min-width="120">
          <template slot-scope="scope"> {{ scope.row.balance }}% </template>
        </el-table-column>
        <el-table-column prop="scan_qr_count" label="扫码次数" min-width="120">
        </el-table-column>
        <el-table-column prop="order_count" label="订单量" min-width="120">
        </el-table-column>
        <el-table-column prop="order_price" label="订单总金额" min-width="120">
          <template slot-scope="scope"> ¥{{ scope.row.order_price }} </template>
        </el-table-column>
        <el-table-column prop="channel_cash" label="总佣金" min-width="120">
          <template slot-scope="scope">
            ¥{{ scope.row.channel_cash }}
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="创建时间" min-width="120">
          <template slot-scope="scope">
            <p>{{ scope.row.create_time | handleTime(1) }}</p>
            <p>{{ scope.row.create_time | handleTime(2) }}</p>
          </template>
        </el-table-column>
      </el-table>

      <lb-page
        :batch="false"
        :page="searchForm.page"
        :pageSize="searchForm.limit"
        :total="total"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
      >
      </lb-page>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
export default {
  components: {},
  data () {
    return {
      base_type: [{ id: 0, title: '全部' }, { id: 1, title: '扫码次数最多' }, { id: 2, title: '订单量最多' }, { id: 3, title: '订单金额最多' }, { id: 4, title: '佣金最多' }],
      loading: false,
      storeList: [],
      searchForm: {
        page: 1,
        limit: 10,
        code: '',
        channel_name: '',
        type: 0
      },
      tableData: [],
      total: 0
    }
  },
  async created () {
    this.getTableDataList()
  },
  methods: {
    resetForm (form) {
      this.$refs[form].resetFields()
      this.getTableDataList(1)
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    },
    getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      this.$api.channel.channelQrList(this.searchForm).then(res => {
        this.loading = false
        if (res.code === 200) {
          this.tableData = res.data.data
          this.total = res.data.total
        }
      })
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-channel-qr-count {
  width: 100%;
  .page-main {
    width: 100%;
    .el-input,
    .el-select,
    .el-input-number {
      width: 200px;
    }
    .dialog-form {
      .el-input,
      .el-select,
      .el-input-number {
        width: 300px;
      }
    }
  }
}
</style>
